package com.googlecode.restitory.api.servlet;

import java.util.List;

import com.googlecode.mycontainer.commons.regex.RegexUtil;

public class ServletHelper {

	private static final String PATTERN_CONTENT_TYPE = "([\\+\\w\\/-]*);{0,1}\\s*(charset=)*(([\\w-]*))";

	public static String getMediaType(String contentType) {
		if (contentType == null) {
			return null;
		}
		List<String> groups = RegexUtil.groups(PATTERN_CONTENT_TYPE,
				contentType);
		if (groups.isEmpty()) {
			return contentType;
		}
		String r = groups.get(1);
		if (r == null || r.length() == 0) {
			return contentType;
		}
		return r;
	}

}
